package net.okjsp;

import junit.framework.TestCase;

public class UnicodeTest extends TestCase {
	public void testCode() {
		String string = "\ud55c\uae00";
		assertEquals("한글",string);
		assertEquals("\\ud55c\\uae00", getUnicoded("한글"));
		assertEquals("\\ud55c1\\uae00", getUnicoded("한1글"));
	}

	private String getUnicoded(String string) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < string.length(); i++) {
			char c = string.charAt(i);
			if (c > 0xff) {
				sb.append("\\u");
				sb.append(Integer.toHexString((int)c));
			} else {
				sb.append(c);
			}
		}
		return sb.toString();
	}
}
